package no.awi.wpd.xml;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import junit.framework.Assert;
import no.awi.wpd.combat.model.ContactZone;
import no.awi.wpd.combat.model.Combat;
import no.awi.wpd.model.ProfileMother;
import no.awi.wpd.unit.model.Profile;
import no.awi.wpd.unit.model.Unit;
import no.awi.wpd.serialize.SerializeService;
import no.awi.wpd.serialize.impl.XmlServiceImpl;

import org.junit.Test;

public class XmlServiceImplIntTest {

	private static final String TEST_TARGET_BASE_DIR = "target/";

	@Test
	public void testSerializeDesializeCombat() throws IOException {
        Combat expected = new Combat();
        
        final Unit badGuys = new Unit();
        badGuys.setFileSize(5);
        badGuys.setModelCount(25);
        Profile badGuysProfile = ProfileMother.dryads();
		badGuys.setProfile(badGuysProfile);
        expected.setBadGuys(badGuys);
        
        final Unit goodGuys = new Unit();
        goodGuys.setFileSize(5);
        goodGuys.setModelCount(25);
        Profile goodGuysProfile = ProfileMother.whiteLion();
		goodGuys.setProfile(goodGuysProfile );
        expected.setGoodGuys(goodGuys);
        
        ContactZone badGuysInContact = new ContactZone();
        badGuysInContact.setModelsInBaseContact(7);
        badGuysInContact.setUnit(badGuys);
        expected.setBadGuysContactZone(badGuysInContact);
        
        ContactZone goodGuysInContact = new ContactZone(badGuysInContact, 5, goodGuys);
        expected.setGoodGuysContactZone(goodGuysInContact);
        
        badGuysInContact.setAttackableOpponent(goodGuysInContact);
		expected.setChargers(goodGuys);
        
		SerializeService xmlService = new XmlServiceImpl();
        xmlService.serialize(expected, new FileWriter(TEST_TARGET_BASE_DIR + "combat.xml"));
        
        Combat actual = xmlService.deserializeCombat(new FileReader(TEST_TARGET_BASE_DIR + "combat.xml"));
        
        Assert.assertEquals("Expected combat is not equal to actual deserialized combat", expected, actual);

	}
	
}
